home *** CD-ROM | disk | FTP | other *** search
- Path: news.iddis.com!jarnot
- From: jarnot@iddis.com (Kevin J. Jarnot)
- Newsgroups: comp.lang.c
- Subject: Re: Variable paramater list macros
- Date: 11 Jan 1996 21:54:56 GMT
- Organization: IDD Information Services
- Message-ID: <JARNOT.96Jan11165456@box10.dstar.iddis.com>
- References: <4crc3v$hm8@barnacle.iol.ie> <TANMOY.96Jan8085718@qcd.lanl.gov>
- Reply-To: jarnot@iddis.com
- NNTP-Posting-Host: box10.dstar.iddis.com
- To: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya),derekh@iol.ie
- In-reply-to: tanmoy@qcd.lanl.gov's message of 08 Jan 1996 15:57:18 GMT
-
- >>>>> "Tanmoy" == Tanmoy Bhattacharya <tanmoy@qcd.lanl.gov> writes:
-
- Derek> In article <4crc3v$hm8@barnacle.iol.ie> derekh@iol.ie (Derek
- Derek> Hardiman) writes:
- Derek> I want to replace a variable
- Derek> argument list function (which I use for debugging ) with a
- Derek> macro that does nothing.
- Derek> Unfortunately I can't remember how to write a macro
- Derek> that takes a variable number of paramaters ! Can you ?
-
- Tanmoy> The question has no answer within the C
- Tanmoy> language. Individual compilers may provide a way. Please
- Tanmoy> ask in a system/compiler specific group.
- Tanmoy> The FAQ has a little to say about this.
-
-
- Actually, this is not 100% true. I use the following macro for debugging
- all the time:
-
- #if defined(DEBUG)
- #define DPRINTF(args) (dprintf args) // Only print when DEBUG is declared
- #else
- #define DPRINTF(args) // O/w, the code won't even be there!
- #endif
-
-
- dprintf() is defined as:
-
- void dprintf(FILE *stream, const char *fmt, ...);
-
-
- Now, the trick is to call DPRINTF() like this:
-
- DPRINTF((stdout, "This is a %s param func.\n", "variable"));
-
-
- Note the double parens. The chars within the internal parens are passed into
- DPRINTF as "args", and the outer remain unexpanded.
-
- Works like a charm.
-
-
- Kevin
-
-
-
- --
- Kevin J. Jarnot - Senior Software Engineer | mailto:jarnot@iddis.com
- IDD Information Services Waltham, MA | http://www-cs.canisius.edu/~jarnot
-